﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using MallInteractiveMap.CMSWebClient.Common;
using MallInteractiveMap.CMSWebClient.Presenter;
using MallInteractiveMap.Language;

namespace MallInteractiveMap.CMSWebClient.Account
{
    public partial class Login : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            if (IsValidLogin(UserName.Text.Trim(), Password.Text.Trim()))
            {
                FormsAuthentication.RedirectFromLoginPage(UserName.Text, RememberMe.Checked);
            }
            else
            {
                ShowMessage(LanguageLoader.GetText("INCORRECT_USER_PASSWORD"), LanguageLoader.GetText("INCORRECT_CREDENTIAL"));
            }
        }
        private bool IsValidLogin(string uName, string passward)
        {
            return new UserPresenter().IsValidUser(uName, passward);
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            SetLanguageAndResources();
        }

        private void SetLanguageAndResources()
        {
            UserNameLabel.Text = LanguageLoader.GetText("USER_NAME");
            PasswordLabel.Text = LanguageLoader.GetText("PASSWORD");
            RememberMeLabel.Text = LanguageLoader.GetText("REMEMBER_ME");
            LoginButton.Text = LanguageLoader.GetText("LOG_IN");
            UserNameRequired.ErrorMessage = UserNameRequired.ToolTip = LanguageLoader.GetText("USER_NAME_REQUIRED");
            PasswordRequired.ErrorMessage = PasswordRequired.ToolTip = LanguageLoader.GetText("PASSWORD_REQUIRED");
        }
    }
}
